// 运行时配置

import { history, RunTimeLayoutConfig } from '@umijs/max';
import RightContent from './components/Layout/RightContent';
import { getAccount } from './services/account';
import '@/assets/css/global.css';
import TopSearch from './components/Layout/Search';
const initUserInfo: API.IUserInfo = { id: -1 };

// 全局初始化数据配置，用于 Layout 用户信息和权限初始化
// 更多信息见文档：https://next.umijs.org/docs/api/runtime-config#getinitialstate
export async function getInitialState(): Promise<API.IUserInfo> {
  const { data } = await getAccount();
  return data || initUserInfo;
}

export const layout: RunTimeLayoutConfig = () => {
  return {
    logo: 'https://img.alicdn.com/tfs/TB1YHEpwUT1gK0jSZFhXXaAtVXa-28-27.svg',
    menu: {
      locale: true,
      type: 'group',
    },
    layout: 'mix',
    fixSidebar: true,
    splitMenus: true,
    rightContentRender: () => <RightContent />,
    menuItemRender: (item, dom) =>
      item.path?.includes('searchInput') ? (
        <TopSearch />
      ) : (
        <div
          style={{ width: '100%' }}
          onClick={() => history.push(item.path ?? '/')}
        >
          {dom}
        </div>
      ),
  };
};
